package com.newtouch.bxzs.database.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.database.config.MyLog;
import com.newtouch.bxzs.database.model.bo.PositionDetailBO;
import com.newtouch.bxzs.database.model.bo.PositionListBO;
import com.newtouch.bxzs.database.model.vo.GetPositionListVO;
import com.newtouch.bxzs.database.model.vo.UpdatePositionStateVO;
import com.newtouch.bxzs.database.model.vo.UpdatePositionVO;
import com.newtouch.bxzs.database.service.PositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 岗位Controller:
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/5 13:41</td>
 * <td>tianshangzhu</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author tianshangzhu
 * @version 1.0.0
 * @since 1.0.0
 */

@RestController
@RequestMapping("/position")
@Api(tags = "后台岗位管理")
@SuppressWarnings("unchecked")
public class PositionController {
    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(PositionController.class);
    @Resource
    private PositionService positionService;

    @PostMapping("/getPositionList")
    @ApiOperation("查询岗位列表信息")
    @MyLog(systemFunctionName = "后台岗位管理", systemFunctionUrl = "/position/getPositionList", userOperationType = 4, userOperationSummary = "查询岗位列表")
    public BaseResponse<IPage<PositionListBO>> getPositionList(@RequestBody GetPositionListVO getPositionListVO) {
        logger.info("查询岗位列表信息");
        IPage<PositionListBO> result = positionService.getPositionList(getPositionListVO);
        // 如果 查询结果为空，返回"没有查询到相应数据"
        if (result == null || result.getTotal() == 0) {
            return RespGenerator.returnOK("没有查询到相应数据");
        }
        return RespGenerator.returnOK(result);
    }

    @GetMapping("/getPositionDetail")
    @ApiOperation("查看岗位详情信息")
    @MyLog(systemFunctionName = "后台岗位管理", systemFunctionUrl = "/position/getPositionDetail", userOperationType = 4, userOperationSummary = "查看岗位详情")
    public BaseResponse<PositionDetailBO> getPositionDetail(@RequestParam @ApiParam(value = "岗位id", required = true) String positionId) {
        logger.info("查看岗位详情信息");
        return RespGenerator.returnOK(positionService.getPositionDetail(positionId));
    }

    @PostMapping("/updatePosition")
    @ApiOperation("添加/修改岗位信息")
    @MyLog(systemFunctionName = "后台岗位管理", systemFunctionUrl = "/position/updatePosition", userOperationType = 5, userOperationSummary = "添加/修改岗位")
    public BaseResponse<String> updatePosition(@RequestBody UpdatePositionVO updatePositionVO) {
        logger.info("添加/修改岗位信息");
        positionService.updatePosition(updatePositionVO);
        return RespGenerator.returnOK("操作成功");
    }

    @PostMapping("/updateState")
    @ApiOperation("启用/禁用岗位")
    @MyLog(systemFunctionName = "后台岗位管理", systemFunctionUrl = "/position/updateState", userOperationType = 2, userOperationSummary = "启用/禁用岗位")
    public BaseResponse<String> updateState(@RequestBody UpdatePositionStateVO updatePositionStateVo) {
        logger.info("启用/禁用岗位");
        positionService.updateState(updatePositionStateVo);
        return RespGenerator.returnOK("操作成功");
    }

    @PostMapping("/deletePosition")
    @ApiOperation("批量删除岗位信息")
    @MyLog(systemFunctionName = "后台岗位管理", systemFunctionUrl = "/position/deletePosition", userOperationType = 3, userOperationSummary = "批量删除岗位")
    public BaseResponse<String> deletePosition(@RequestBody @ApiParam(value = "岗位id数组,不用传参数名", required = true) List<String> positionIdList) {
        logger.info("批量删除岗位信息");
        positionService.deletePosition(positionIdList);
        return RespGenerator.returnOK("删除成功");
    }
}
